<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!doctype html>
<html>
<head>
<style type="text/css">
* {
	margin: 0px;
	padding: 0px;
	font-size: 12px;
}
</style>
</head>
<body class="gray-bg">

	<!-- 隐藏域 -->
	<input type="hidden" value="${replaceId}" id="replaceId"
		name="replaceId" />
	<input type="hidden" value="${busiId}" id="busiId" name="busiId" />
	<input type="hidden" value="${modeId}" id="modeId" name="modeId" />
	<input type="hidden" id="dkId" />
	<!-- 隐藏域 -->

	<div class="container creditbody">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;垫款调整A</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="buttonfixed" style="display: none;" id="buttonfixed">
			<button type="button" id="save" style="display: none;"
				class="btn dpbtn_blue" onclick="saveOrUpdate();">保存</button>
			<button type="button" id="update" style="display: none;"
				class="btn dpbtn_blue" onclick="saveOrUpdate();">修改</button>
		</div>
		<div class="ibox-content ibox-con">
			<%@include file="/jsp/common_yw_include.jsp"%>
			<div class="business-manwife">业务进程</div>
			<div class="business-padding" id="">
				<table class="yw-course">
					<thead>
						<tr>
							<th id="added_status1" equal="0" class="splztab bg-grey">按揭日报表</th>
							<th id="dianzi" equal="30" class="splztab bg-grey">申请垫资
								</li>
							<th id="M_cwshy" equal="50" class="splztab bg-grey">财务审核1</th>
							<th id="M_cwshe" equal="200" class="splztab bg-grey">财务审核2</th>
							<th id="caiwudiankuan" class="splztab bg-grey">财务垫款</th>
							<th id="" class="splztab bg-green">垫款调整A</th>
							<th id="" class="splztab">申请垫款调整Ｂ</th>
							<th id="" class="splztab">垫款调整Ｂ审核</th>
							<th id="" class="splztab">垫款调整Ｂ</th>
							<th id="" class="splztab">财务退款</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
		<div class="business-manwife">协议资料</div>
		<%@include file="/jsp/xieyi_zi_liao.jsp"%>

		<div class="business-manwife">申请垫资信息</div>
		<div class="tche-padding">
			<table cellpadding="0" cellspacing="0" border="0" class="infor-table">
				<tr>
					<td align="right"><label class="control-label np">提车时间：</label>
					</td>
					<td>
						<div class="control-div np" id="dateFist">
							<fmt:formatDate value='${ywFundApply.dateFist}'
								pattern='yyyy-MM-dd HH:mm' />
						</div>
					</td>
				</tr>
			</table>
			<ul class="zxsearch-ulsd" style="margin-top: 15px;">
				<li class="zxsearch-ulli" style="margin: 0px;">信息备注：</li>
				<li class="zxsearch-ullib">${ywFundApply.remarks }</li>
			</ul>
		</div>

		<div class="business-manwife">费用明细</div>
		<div class="tche-padding">
			<table cellpadding="0" cellspacing="0" border="0" class="thead-table padding-wangge">
				<thead class="thead-a">
					<tr>
						<th class="warn-red-bold">贷款本金</th>
						<th class="warn-red-bold">签约贷款额</th>
						<c:if test="${!empty fundItems_ }">
							<c:forEach items="${fundItems_ }" var="fundItem_" varStatus="status">
								<th class="warn-red-bold">${fundItem_.name }</th>
							</c:forEach>
						</c:if>
					</tr>
				</thead>
				<tbody class="tbody-a">
					<tr>
						<td class="zxyjred"><fmt:formatNumber type="number" value="${empty ywBusinessLoan.loanAmount ? 0 : ywBusinessLoan.loanAmount}" pattern="0.00" maxFractionDigits="2" /></td>
						<td class="zxyjred"><fmt:formatNumber type="number" value="${empty ywBusinessLoan.signLoanAmount ? 0 :  ywBusinessLoan.signLoanAmount}" pattern="0.00" maxFractionDigits="2" /></td>
						<c:if test="${!empty fundItems_ }">
							<c:forEach items="${fundItems_ }" var="fundItem_" varStatus="status">
								<td class="zxyjred"><fmt:formatNumber type="number" value="${empty fundItem_.feeCount ? 0 : fundItem_.feeCount}" pattern="0.00" maxFractionDigits="2" /></td>
							</c:forEach>
						</c:if>
					</tr>
				</tbody>
			</table>
			<c:choose>
				<c:when test="${!empty fundItems }">
					<ul class="thead-tableul">
						<c:forEach items="${fundItems }" var="cwFundItem"
							varStatus="status">
							<c:if test="${status.index % 7 == 0 }">
								<li>
									<table cellpadding="0" cellspacing="0" border="0"
										class="thead-table">
										<thead class="thead-a">
											<tr>
												<th></th>
												<th>应收</th>
												<th>实收</th>
											</tr>
										</thead>
										<tbody class="tbody-a">
												</c:if>
												<tr>
													<td
														<c:if test="${cwFundItem.key == '03'}"> style="color:#FC1515;"</c:if>
														<c:if test="${cwFundItem.key == '25'}"> style="color:#FC1515;"</c:if>>${cwFundItem.name }
													</td>
													<td <c:if test="${cwFundItem.key == '03'}"> style="color:#FC1515;"</c:if>
														<c:if test="${cwFundItem.key == '25'}"> style="color:#FC1515;"</c:if> id="fee_td_${cwFundItem.key }">
														<fmt:formatNumber type="number" value="${cwFundItem.feeCount }" pattern="0.00" maxFractionDigits="2" /></td>
													<td <c:if test="${cwFundItem.key == '03'}"> style="color:#FC1515;"</c:if>
														<c:if test="${cwFundItem.key == '25'}"> style="color:#FC1515;"</c:if> id="remit_td_${cwFundItem.key }">
														<fmt:formatNumber type="number" value="${cwFundItem.remitCount }" pattern="0.00" maxFractionDigits="2" /></td>
												</tr>
												<c:if test="${status.index % 7 == 6  || status.last}">
											</tbody>
									</table>
								</li>
							</c:if>
						</c:forEach>
					</ul>
				</c:when>
				<c:otherwise>
        			没有收费项目
        		</c:otherwise>
			</c:choose>
			<ul class="thead-tableul">
				<li>
					<table cellpadding="0" cellspacing="0" border="0"
						class="thead-table">
						<thead class="thead-a">
							<tr>
								<th></th>
								<th>应收</th>
								<th>实收</th>
							</tr>
						</thead>
						<tbody class="tbody-a">
							<tr>
								<td class="npb style-red">应收合计</td>
								<td><fmt:formatNumber type="number"
										value="${fundTotal.feeCount }" pattern="0.00"
										maxFractionDigits="2" /></td>
								<td><fmt:formatNumber type="number"
										value="${fundTotal.remitCount }" pattern="0.00"
										maxFractionDigits="2" /></td>
							</tr>
						</tbody>
					</table>
				</li>
			</ul>
		</div>
		<div class="business-manwife">返利信息</div>
		<div class="tche-padding">
			<table cellpadding="0" cellspacing="0" border="0" class="infor-table">
				<tr>
					<td align="right"><label class="control-label np">经销商返利：</label>
					</td>
					<td>
						<div class="control-div np">${ywFees.rebateDealer}</div>
					</td>
					<td align="right"><label class="control-label np">分公司展业费：</label>
					</td>
					<td>
						<div class="control-div np">${ywFees.rebateProvince}</div>
					</td>
				</tr>
				<tr>
					<td align="right"><label class="control-label np">区域&业务员展业费：</label>
					</td>
					<td>
						<div class="control-div np">${ywFees.rebateArea}</div>
					</td>
					<td align="right"><label class="control-label np">返利方式：</label>
					</td>
					<td>
						<div class="control-div np" id="">${empty ywFees.rebateTypeDisplay ? '-' : ywFees.rebateTypeDisplay}
					</td>
				</tr>
			</table>
		</div>

		<form class="form-horizontal" id="commentForm">
			<div class="business-manwife">财务调整信息</div>
			<div class="tche-padding">
				<table cellpadding="0" cellspacing="0" border="0"
					class="buyinfor-table">
					<tr>
						<td align="right"><label class="control-label np">调整金额：</label>
						</td>

						<td><input class="form-control" type="text" id="amountAdjust"
							name="amountAdjust" required="required" placeholder="调整金额(必填)" />
						</td>
						<td><select class="form-control" id="remitAdjustType"
							name="remitAdjustType" style="width: 100px;">
								<option value="1">收款</option>
								<option value="2">付款</option>
						</select></td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">打款时间：</label>
						</td>
						<td><input class="laydate-icon form-control"
							placeholder="打款时间(必填)" required="required" type="text"
							id="timeRemit" name="timeRemit" onclick="laydate();" /></td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">到账时间：</label>
						</td>
						<td><input class="laydate-icon form-control"
							placeholder="到账时间" type="text" id="timeArrive" name="timeArrive"
							onclick="laydate();" /></td>
						<td align="right"><label class="control-label np">财务审核人：</label>
						</td>
						<td><input id="nameAuditor" name="nameAuditor"
							placeholder="财务审核人(必填)" required="required" class="form-control" />
						</td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">财务审核时间：</label>
						</td>
						<td><input class="laydate-icon form-control"
							placeholder="财务审核时间" type="text" id="timeAudit" name="timeAudit"
							onclick="laydate();" /></td>
						<td align="right"><label class="control-label np">财务档案编号：</label>
						</td>
						<td><input id="financialRecordsNumber"
							placeholder="财务档案编号(必填)" required="required"
							name="financialRecordsNumber" placeholder="财务档案编号"
							class="form-control" /></td>
					</tr>
				</table>
			</div>
			<div class="business-manwife">经办信息</div>
			<div class="tche-padding">
				<table cellpadding="0" cellspacing="0" border="0"
					class="buyinfor-table">
					<tr>
						<td align="right"><label class="control-label np">经办人：</label>
						</td>
						<td><input class="form-control" type="text" id="uname"
							name="uname" placeholder="经办人" value="${current_user_key.uname}"
							readonly="readonly" /></td>
						<td align="right"><label class="control-label np">经办时间：</label>
						</td>
						<td><input id="jbTime" name="jb_time" placeholder="经办时间(必填)"
							required="required" class="laydate-icon form-control"
							onclick="laydate();" /></td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>
	<!-- layerDate plugin javascript -->
	<script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>
	<!-- custom js -->
	<%@include
		file="/js/common-dpqc/dpqc-validate/comm_validate_include.jsp"%>
	<script type="text/javascript"></script>
	<!-- 
 	    作者：程立勇
 	   描述：js脚本
 	 -->
	<script type="text/javascript">
 	
	 	$(function(){
	 		getDataInfoByBusiId();
	 	});
	 	
	 	
		$(function(){
	        $("#commentForm").validate({
	        	 rules: {
	        		 amountAdjust:{
	        			 allMoney:true
	        		 }
	        	 },
			    //重写showErrors
		        showErrors: function (errorMap, errorList) {
		        	$.each(errorList, function (i, v) {
		        		layer.tips(v.message, v.element, { time: 1500 });
		        		
		                return false;
		            });
		        },
		        /* 失去焦点时验证 */
		        onfocusout: function(element) {$(element).valid(); },
		        /*  键盘抬起不验证 */
		        onkeyup:false,
		    });
		});
	 	
	 	var getDataInfoByBusiId=function(){
	 		var data={};
	 		data.busiId=$.getUrlData("id");
	 		$.dpAjax({
	    		url:'${basePath}/CwRemitAdjustAController/selectRefined',
	    		data:data,
   				success: function(datas){
	    			  if(datas.flag == "100100")
					  {
	    				  if(datas.result!=null){
	    					  var data=datas.result;
	    					  $("#dkId").val(data.replaceId);
	    					  $("#buttonfixed").show();
	    					  $("#update").show();
	    					  $("#save").hide();
	    					  $("#amountAdjust").val(data.amountAdjust);
	    					  var t1 = document.getElementById("remitAdjustType");   
	    		      	        for(i=0;i<t1.length;i++){//给select赋值  
	    		      	            if(data.remitAdjustType==t1.options[i].text){  
	    		      	                t1.options[i].selected=true  
	    		      	            }  
	    		      	        }
	    						$("#timeRemit").val(data.timeRemit);
	    						$("#timeArrive").val(data.timeArrive);
	    						$("#nameAuditor").val(data.nameAuditor);
	    						$("#timeAudit").val(data.timeAudit);
	    						$("#financialRecordsNumber").val(data.financialRecordsNumber);
	    						$("#jbTime").val(data.jbTime);
	    						$("#uname").val(data.modifierName);
	    				  }else{
	    					  $("#buttonfixed").show();
	    					  $("#save").show();
	    					  $("#update").hide();
	    				  }
	    				  layer.msg('执行成功！', {icon: 6});
						  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
                }
	    	});
	 	}
	 	var saveOrUpdate=function(){
			var data={};
			var dkId=$("#dkId").val();
			var url='${basePath}/CwRemitAdjustAController/save';
			if(dkId!=""){
				data.id=dkId;
				url='${basePath}/CwRemitAdjustAController/modify';
			}
			data.cusId=$("#customerId").val();
			data.busiId=$.getUrlData("id");
			data.amountAdjust=$("#amountAdjust").val();
			data.remitAdjustType=$('#remitAdjustType option:selected').text();
			data.timeRemit=$("#timeRemit").val();
			data.timeArrive=$("#timeArrive").val();
			data.nameAuditor=$("#nameAuditor").val();
			data.timeAudit=$("#timeAudit").val();
			data.financialRecordsNumber=$("#financialRecordsNumber").val();
			var validstatus = $("#commentForm").valid();
			if(validstatus){
				$.dpAjax({
		    		url:url,
		    		data:data,
	   				success: function(datas){
		    			  if(datas.flag == "100100")
						  {
		    				  layer.msg('执行成功！', {icon: 6});
							  return;
						  }
						  if(datas.flag == "100200")
		                  {
							  $.fn.showDatas({"datas":datas});
		                	  return;
		                  }
	                }
		    	});
			}else{
				layer.msg('有验证未通过，请仔细检查！', {icon: 5});
			}
	 	}
	</script>
</body>
</html>
